import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:seedfour/app/constants.dart';
import 'package:seedfour/app/theme.dart';

import 'logic.dart';

class BalanceRecordDetailPage extends StatelessWidget {
  BalanceRecordDetailPage({Key? key}) : super(key: key);

  final logic = Get.find<BalanceRecordDetailLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('收支详情'),
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back_ios,
            size: 16.w,
          ),
          onPressed: () {
            Get.back();
          },
        ),
      ),
      body: Padding(
        padding: EdgeInsets.all(kSpaceSmall),
        child: Column(
          children: [
            Container(
              width: double.infinity,
              padding: EdgeInsets.all(kSpaceMedium),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(kSpaceSmall),
              ),
              child: Column(
                children: [
                  _buildTitle(),
                  const Divider(),
                  SizedBox(height: kSpaceLarge),
                  _buildItem('类别',
                      logic.recordDetail.changeSubtype == 1 ? '收入' : '支出'),
                  SizedBox(height: kSpaceLarge),
                  _buildItem(
                      '时间',
                      DateFormat('yyyy.MM.dd HH:mm:ss').format(
                          DateTime.fromMillisecondsSinceEpoch(
                              logic.recordDetail.createdAt!))),
                  SizedBox(height: kSpaceLarge),
                  _buildItem('余额', logic.recordDetail.afterBalance ?? ''),
                  SizedBox(height: kSpaceLarge),
                  _buildItem('备注', logic.recordDetail.remark ?? ''),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildItem(String title, String value) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          title,
          style: TextStyle(
              fontSize: kFontSizeSmall, color: AppColor.colorFontBlack),
        ),
        SizedBox(width: kSpaceHuge),
        Expanded(
          child: Text(
            value,
            textAlign: TextAlign.end,
            style: TextStyle(
                fontSize: kFontSizeSmall, color: AppColor.colorFontBlack),
            softWrap: true,
          ),
        ),
      ],
    );
  }

  Widget _buildTitle() {
    return Column(
      children: [
        SizedBox(height: kSpaceMedium),
        Text(
          logic.recordDetail.title ?? '',
          style: TextStyle(
            fontSize: kFontSizeMini,
            color: AppColor.colorFontBlack,
          ),
        ),
        SizedBox(height: kSpaceSmall),
        Text(
          logic.recordDetail.changeSubtype == 1
              ? '+${logic.recordDetail.amount?.replaceAll('¥', '')}'
              : '-${logic.recordDetail.amount?.replaceAll('¥', '')}',
          style: TextStyle(
            fontSize: 30.sp,
            fontWeight: AppFont.fontMedium,
          ),
        ),
        SizedBox(height: kSpaceLarge),
      ],
    );
  }
}
